{extend name="user-layout" /}
{block name="content"}
<div class="content-wrapper">
    <div class="row">
        <div class="col-md-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    <h4 class="card-title">API信息</h4>
                    <form class="layui-form forms-sample" action="" method="post">
                        <input name="u[id]" value="{$api.id}" hidden disabled readonly>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">APP ID</label>
                            <div class="col-sm-9">
                                <input type="text" name="u[uid]" value="{$api.uid}" class="form-control"
                                    placeholder="UID" readonly>
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label">APP KEY</label>
                            <div class="col-sm-9">
                                <input id="txtKey" type="text" name="u[key]" value="{$api.key}" class="form-control"
                                    readonly>
                            </div>
                            <div class="col-sm-1">
                                <button id="btnResetKey" type="button" class="btn btn-danger">重置</button>
                            </div>
                        </div>
                        <!-- <div class="form-group row">
                            <label class="col-sm-2 col-form-label">访问域名</label>
                            <div class="col-sm-9">
                                <input type="text" name="u[domain]" value="{$api.domain|default='localhost'}" class="form-control" placeholder="请输入访问域名">
                            </div>
                        </div> -->
                        <!-- <div class="form-group row">
                            <label class="col-sm-2 col-form-label">数据公钥</label>
                            <div class="col-sm-9">
                                <textarea type="text" name="u[secretkey]" required lay-verify="required" class="form-control" rows="5">{$api.secretkey}</textarea>
                                <p class="card-description">商户数据公钥可以自己生成,推荐使用支付宝<a href="https://docs.open.alipay.com/291/106097" target="_blank">RSA签名验签工具</a>（注：非JAVA适用 2048 pkcs1s）</p>
                            </div>
                        </div> -->
                        <!-- <div class="form-group row">
                            <label class="col-sm-2 col-form-label">IP白名单</label>
                            <div class="col-sm-9">
                                <textarea type="text" name="u[auth_ips]" class="form-control"
                                    rows="5">{$api.auth_ips|default='127.0.0.1'}</textarea>
                                <p class="card-description">全IP或者IP段(192.168.*.*或者192.168.1.1)</p>
                            </div>
                        </div> -->
                        <div class="form-group row">
                            <label class="col-sm-2 col-form-label"></label>
                            <div class="col-sm-9">
                                <button type="button" class="btn btn-primary btn-submit-apiinfo btn-fw" lay-submit
                                    lay-filter="app-user-submitapi">提交修改</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
        <!-- <div class="col-md-12 grid-margin stretch-card">
            <div class="card">
                <div class="card-body">
                    <h4 class="card-title">平台公钥</h4>
                    <p class="card-description">平台支付请求以及数据验签都需要</p>
                    <textarea id="clipboard" readonly class="form-control" rows="5">{$rsa.value}</textarea>
                    <div class="mt-3">
                        <button type="button" class="btn btn-primary btn-clipboard" data-clipboard-action="copy" data-clipboard-target="#clipboard">复制</button>
                    </div>
                </div>
            </div>
        </div> -->
    </div>
</div>
{/block}
{block name="pagejs"}
<script src="__STATIC__/cloudui/js/clipboard.js"></script>
<script type="text/javascript">
    layui.use(['form'], function () {
        let $ = layui.$,
            form = layui.form;

        $('#btnResetKey').click(function () {
            //提交
            $.ajax({
                url: '{:url(\'index/Api/resetkey\')}',
                method: "POST",
                cache: false,
                success: function (res) {
                    $('#txtKey').val(res.data);
                    layer.alert(res.msg, {
                        icon: 1,
                        closeBtn: 0,
                        shade: 0.6
                    });
                }
            });
        });

        //监听搜索
        form.on('submit(app-user-submitapi)', function (data) {
            let field = data.field;
            console.log(field)
            //提交
            $.ajax({
                url: '{:url(\'index/Api/index\')}',
                method: "POST",
                data: field,
                success: function (res) {
                    if (res.code == 1) {
                        setTimeout("location.reload();", 1000);
                    }
                    showToast(res);
                }
            });
        });
    });
</script>
{/block}